package ar.edu.caece.compiler.grammar.factories;

import ar.edu.caece.compiler.grammar.AbstractTokenVisitorFactory;
import ar.edu.caece.compiler.grammar.TokenVisitor;

public class PROPFactory extends AbstractTokenVisitorFactory {

	private static PROPFactory INSTANCE;
	
	private PROP1Factory prop1Factory;
	private PROP2Factory prop2Factory;
	private PROP3Factory prop3Factory;
	private PROP4Factory prop4Factory;
	private PROP5Factory prop5Factory;
	private PROP6Factory prop6Factory;


	
	public static PROPFactory getInstance() throws Exception {
		if(INSTANCE==null) INSTANCE = new PROPFactory();
		return INSTANCE;
	}
	
	private Initializer initializer = new Initializer() {
		
		@Override
		public void init() throws Exception {
			initializer = NoOperationInitializer.getInstance();
			prop1Factory = PROP1Factory.getInstance();
			prop2Factory = PROP2Factory.getInstance();
			prop3Factory = PROP3Factory.getInstance();
			prop4Factory = PROP4Factory.getInstance();
			prop5Factory = PROP5Factory.getInstance();
			prop6Factory = PROP6Factory.getInstance();
		}			

	};
	
	private PROPFactory() throws Exception {

	}
	
	@Override
	public TokenVisitor makeChainedVisitor(
			final TokenVisitor siguiente) throws Exception {
		initializer.init();

		return prop1Factory.makeChainedVisitor(prop2Factory.makeChainedVisitor(prop3Factory.makeChainedVisitor(prop4Factory.makeChainedVisitor(prop5Factory.makeChainedVisitor(prop6Factory.makeChainedVisitor(siguiente))))));
	
	}
	@Override
	public TokenVisitor makeVisitor() throws Exception {
		initializer.init();

		return prop1Factory.makeChainedVisitor(prop2Factory.makeChainedVisitor(prop3Factory.makeChainedVisitor(prop4Factory.makeChainedVisitor(prop5Factory.makeChainedVisitor(prop6Factory.makeVisitor())))));
	}
	
	
}
